package com.cloud.server.service.user.impl;

import com.cloud.server.domain.user.UserIntegral;
import com.cloud.server.mapper.user.UserIntegralMapper;
import com.cloud.server.service.user.UserIntegralService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuyuan
 * @since 2021-11-22
 */
@Service
public class UserIntegralServiceImpl extends ServiceImpl<UserIntegralMapper, UserIntegral> implements UserIntegralService {
    @Autowired
    UserIntegralMapper userIntegralMapper;
    @Override
    public UserIntegral getByUserId(Long id) throws Exception {
        if(id == null){
            throw new Exception("没有此用户");
        }
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("user_id",id);
        List<UserIntegral> userIntegrals = userIntegralMapper.selectByMap(stringObjectHashMap);
        if(userIntegrals.size() != 1){
            throw new Exception("用户异常");
        }
        return userIntegrals.get(0);
    }
}
